package com.tvsinfo.jdk.demo.case2_function_interface;

import com.tvsinfo.jdk.demo.case2_function_interface.dto.OrderPageRequest;
import com.tvsinfo.jdk.demo.case2_function_interface.dto.OrderStatusEnum;
import com.tvsinfo.jdk.demo.case2_function_interface.dto.OrderTypeEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class FunctionDemo3 {


    public static void main(String[] args) {
        OrderPageRequest orderPageRequest = new OrderPageRequest();
        orderPageRequest.setInOrderStatuses(Arrays.asList(3, 10));
        orderPageRequest.setInOrderTypes(Arrays.asList(1, 2));

        FunctionDemo3 functionDemo3 = new FunctionDemo3();
        functionDemo3.serach(orderPageRequest);
    }


    public void serach(OrderPageRequest orderPageRequest) {
        OrderPageRequest newPageRequest = new OrderPageRequest();

        //订单状态
        Collection<Integer> inOrderStatuses = orderPageRequest.getInOrderStatuses();

        Function<OrderStatusEnum, Integer> orderStatusEnumIntegerFunction = OrderStatusEnum::getKey;
//        Function<OrderStatusEnum, Integer> orderStatusEnumIntegerFunction2 = orderStatusEnum -> orderStatusEnum.getKey();
//        Function<OrderStatusEnum, Integer> orderStatusEnumIntegerFunction3 = (OrderStatusEnum orderStatusEnum) -> orderStatusEnum.getKey();

        newPageRequest.setInOrderStatuses(getCurStatus(inOrderStatuses, OrderStatusEnum::getByOldKey, orderStatusEnumIntegerFunction));


        //订单类型
        Collection<Integer> inOrderTypes = orderPageRequest.getInOrderTypes();
        Function<OrderTypeEnum, Integer> integerFunction = OrderTypeEnum::getKey;
        newPageRequest.setInOrderTypes(getCurStatus(inOrderTypes, OrderTypeEnum::getByOldType, integerFunction));

        //支付字段
        System.out.println(newPageRequest);
    }

    public Collection<Integer> getCurStatus(Collection<Integer> integers, Function<Integer, List> olTo, Function newFrom) {
        Collection<Integer> integers1 = new ArrayList<>();
        integers.forEach(integer -> {
            List newInteger = olTo.apply(integer);
            List<Integer> newList = (List<Integer>) newInteger.stream().map(newFrom).collect(Collectors.toList());
            integers1.addAll(newList);
        });
        return integers1;
    }


}
